package com.swak.consistency.core.resolve.impls;

import org.springframework.core.Ordered;

import com.swak.consistency.core.attribute.ConsistencyAttribute;
import com.swak.consistency.core.context.ConsistencyContext;
import com.swak.consistency.core.context.ThreadContext;
import com.swak.consistency.core.resolve.ContextResolver;

/**
 * 优先从本地线程上上文获取
 * 
 * @author DELL
 */
public class ThreadLocalResolver<T extends ConsistencyContext> implements ContextResolver<T> {

	@Override
	@SuppressWarnings("unchecked")
	public T acquire(ConsistencyAttribute attribute) {
		return (T) ThreadContext.get(attribute.getScheme());
	}

	@Override
	public int getOrder() {
		return Ordered.HIGHEST_PRECEDENCE;
	}
}
